home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Macintosh Tracker Folder / Technical Notes < prev    next >
Text File  |  1993-07-07  |  8KB  |  125 lines

  1. Technical Notes for Macintosh Tracker 1.0.0
  2.  
  3.  
  4. This document describes what I did to get Tracker 3.10 to run on the Macintosh.  This information should help you if you want to get any future versions of Tracker to run.  Please see the file "Tracker AEIMP Protocol" to see how the programs communicate.
  5.  
  6. The program was build with Think C 5.0.  I've included everything necessary to build the server for Tracker 3.10.
  7.  
  8. If you are going to work with the Tracker source code, PLEASE read this document COMPLETELY before starting.
  9.  
  10.  
  11. •    Macintosh Files
  12.  
  13. Here's a description of the special files I created to work with the Macintosh (and modifications to other files):
  14.  
  15. "altered_audio.c"
  16. This replaces the file "audio.c".  There are two changes in the file.  First, the function called "resample" has been commented out because I replace it with my own in a different part of the program.  Second, the "/ oversample" in the function "create_step_table" has been removed.  This is necessary because the Macintosh port doesn't support oversampling.  Instead I use antialiasing.  But to keep things portable, I did not change any other part of the program dealing with oversampling, so the tracker thinks it's doing oversampling.  You'll know immediately if you forgot to do this:  everything will be played one octave lower.
  17.  
  18. "mac_audio.c"
  19. This is the Macintosh specific audio driver file.  It contains my modified version of "resample" as well as the standard audio control functions used by the program.  Check out "linux_audio.c", "sgi_audio.c", and "ss10_audio.c" in the original tracker source folder to see how this code interacts with the rest of Tracker on a general level.
  20. Note that there are lots of extra functions in "mac_audio.c" which I needed to add.
  21.  
  22. "mac_events.c"
  23. This contains the tools used to send and receive Apple Events with the client program, as well as an event function used to release the processor to other programs and look for more Apple Events.
  24.  
  25. "mac_hack.c"
  26. This is the granddaddy file.  It contains the real "main" function which sets up the fake command line to be sent to the tracker's "main" function.  It contains degenerate versions of many of the ANSI functions tracker uses as well as functional replacements for the important functions, such as "fopen".  "mac_hack.c" also includes the necessary functions for the tracker which were contained in "termio.c".  Since the Macintosh doesn't deal with terminals, I just eliminated it and put degenerate forms of the functions in.
  27.  
  28. "mac_hack.h"
  29. This is what I use to override the ANSI functions.  It includes the standard ANSI headers and then uses the #define directive to redefine the standard functions to my own functions.  Note in "mac_hack.h" I redefine the function "main" so that MY main function gets called.  Also note in "mac_hack.c" how I #undef main before declaring the function so that it has the proper name for the linker (so I don't get hoist by my own petard).  All this is great compiler hackery.
  30.  
  31. "read.c"
  32. See note below about "Antialiasing" to see what I did to this poor file!
  33.  
  34.  
  35. •    Libraries
  36.  
  37. In order to build tracker, you need some libraries.  Specifically, the following:
  38.  
  39. "ANSI-small int=4"
  40. "MacTraps"
  41. "MacTraps2"
  42. "SANE"
  43.  
  44. The only problem is the first one.  To create this, make a copy of the "ANSI-small" library that came with your THINK C 5.0 package.  Open it.  Under "Options...Compiler Settings", ENABLE 4-byte integers (because Tracker assumes it runs under UNIX where sizeof(int)==4).  Then rebuild the library.
  45.  
  46.  
  47. •    Fake "standard" header files
  48.  
  49. Tracker assumes that the header file <malloc.h> is available.  Since it isn't standard ANSI, make a <malloc.h> file containing the following line:
  50.  
  51. #include <stdlib.h>
  52.  
  53. Then put it in the "headers" folder in the THINK C search path.  This will include the true malloc prototypes, which is what the source code is expecting.
  54.  
  55.  
  56. •    Other settings
  57.  
  58. Just as the ANSI library must have 4-byte integers on, the entire program needs 4-byte integers.  My project file has this set properly, but if you are using MPW, you will have to make your own, so take note of this.
  59.  
  60. 68020 instructions are ON.  FPU instructions are OFF.  For MPW people:  the code conditionally compiles 68020 or 68000 instructions in "mac_audio.c" depending on whether or not the option is set in the "Options..." dialog of THINK C.  I don't know if the #if directives I used will work under MPW, so you may have to go and put your equivalent directives in.  There's a couple of conditional compilation directives in "mac_hack.h" as well involving this.
  61.  
  62. Finally, the source code assumes that the following occurs in the prefix header:
  63.  
  64. #include <MacHeaders>
  65. #include "mac_hack.h"
  66.  
  67. This sets up the mac_hackery without requiring alteration of each source file.
  68.  
  69.  
  70. •    What happens with a new version?
  71.  
  72. First, if it uses ANSI or UNIX functions which the current version doesn't, they will call out to the real ANSI-small library instead of my mac_hackery.  This could cause serious problems.  To find out if there are any new functions, REMOVE the ANSI-small library from the project and choose "Check Link" from the Project menu.  The following functions ARE used from the ANSI library (otherwise it wouldn't be required):
  73.  
  74. [This is a dump of my "Link Failed" window]
  75. undefined: atexit (mac_hack.c)
  76. undefined: exit (mac_hack.c)
  77. undefined: sscanf (main.c, tools.c)
  78. undefined: sprintf (open.c, mac_hack.c)
  79. undefined: strlen (dump_song.c, getopt.c, open.c, read.c)
  80. undefined: strcmp (main.c)
  81. undefined: strncmp (dump_song.c)
  82. undefined: strchr (open.c)
  83. undefined: tolower (getopt.c, open.c)
  84. undefined: strcpy (open.c, read.c)
  85. undefined: strncpy (open.c)
  86.  
  87. WATCH FOR ANY UNDEFINED FUNCTIONS OTHER THAN THESE!!!  If there are other undefined functions than these, you will have to use your judgement as to what you should do.  Generally:
  88.  
  89. a)  If the function is an "internal" function (such as the string functions above), which don't "touch" things outside of the program, it is OK to use the ANSI version.
  90.  
  91. b)  If the function "touches" part of the operating system (such as fopen, fgetc, and printf), you'll have to write your own version which works with the framework I've established.
  92.  
  93. USE YOUR JUDGEMENT!
  94.  
  95.  
  96. •    Note about Antialiasing (i.e. changes to the file "read.c")
  97.  
  98. Antialiasing works by doing a linear interpolation between the sample point immediately to the left of the index into the sample (round down) and the one immediately to the right (round up).  Espie's code ensures that the rounded DOWN value of the pointer will never exceed the length of the sample.  However, rounding up may violate this.  As a result, when antialiasing is used, an undefined byte immediately after the last valid sample byte may be touched.  This is not too serious, but to make things work perfectly, I have modified one of the functions in "read.c".  The function is "read_sample".  Find it and replace it with this version:
  99.  
  100. LOCAL void read_sample(struct sample_info *info, FILE *f)
  101.   {
  102.     if (info->start)
  103.       {
  104.         fread(info->start, 1, info->length, f);
  105.         if (info->rp_start)
  106.           {
  107.             /* if sample loops, then append first loop sample to end */
  108.             info->start[info->length] = info->start[info->rp_offset];
  109.           }
  110.          else
  111.           {
  112.             /* otherwise, append last sample */
  113.             info->start[info->length] = info->start[info->length - 1];
  114.           }
  115.       }
  116.   }
  117.  
  118. In order to do this without corrupting the heap, one must also change the way the sample tables are allocated.  However, my replacement for "calloc" always allocates one extra byte, so this shouldn't be a problem.
  119.  
  120.  
  121. ----------------
  122. Thomas R. Lawrence
  123.  
  124. tomlaw@world.std.com
  125.